import socket

# Connect to the server at the given location
def connect_to_server():
    serverSock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    serverSock.connect(("localhost",1234))
    return serverSock

# Disconnect from the server
def disconnect(serverSock):
    send_msg("BYE");
    serverSock.close()

# Send a message to the server
def send_msg(serverSock, msg):
    bmsg = bytes(msg+"\n", "UTF-8")
    serverSock.sendall(bmsg)

# Sends a signal to the monitoring server to let it know simulations have begun.
def send_start_signal(serverSock):
    send_msg(serverSock, "SIMSTART")

# Sends a signal to the monitoring server to let it know simulations have stopped.
def send_stop_signal(serverSock):
    send_msg(serverSock, "SIMSTOP")

# Sends a signal to the monitoring server to let it know a simulation has completed.
def send_confirmation(serverSock, width, trace, z_im):
    send_msg(serverSock, "SIMCOMP "+str(trace)+" "+str(width)+" "+str(z_im))